<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组的平方</title>
</head>

<body>
  <script>
    var sortedSquares = function (nums) {
      //先将数组的每项更新成它的平方，再进行从小到大的排序
      return nums.map(i => {
        return i = i ** 2
      }).sort((a, b) => a - b)
    };
    console.log(sortedSquares([-4, -1, 0, 3, 10])); //[0,1,9,16,100]
  </script>
</body>

</html>